/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.gal.GalSearchControl;
/*     */ import com.zimbra.cs.gal.GalSearchParams;
/*     */ import com.zimbra.cs.gal.GalSearchResultCallback;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.type.GalSearchType;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SearchGal
/*     */   extends AdminGalDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  49 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  54 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  56 */     String domainName = request.getAttribute("domain");
/*  57 */     Provisioning prov = Provisioning.getInstance();
/*  58 */     Domain domain = prov.get(Key.DomainBy.name, domainName);
/*  59 */     if (domain == null) {
/*  60 */       throw AccountServiceException.NO_SUCH_DOMAIN(domainName);
/*     */     }
/*  62 */     checkDomainRight(zsc, domain, Rights.Admin.R_accessGAL);
/*     */     
/*  64 */     String name = request.getAttribute("name", "");
/*  65 */     int limit = (int)request.getAttributeLong("limit", 0L);
/*  66 */     String typeStr = request.getAttribute("type", GalSearchType.account.name());
/*  67 */     GalSearchType type = GalSearchType.fromString(typeStr);
/*     */     
/*  69 */     String galAcctId = request.getAttribute("galAcctId", null);
/*     */     
/*  71 */     String token = request.getAttribute("token", null);
/*     */     
/*  73 */     GalSearchParams params = new GalSearchParams(domain, zsc);
/*  74 */     if (token != null)
/*  75 */       params.setToken(token);
/*  76 */     params.setType(type);
/*  77 */     params.setRequest(request);
/*  78 */     params.setQuery(name);
/*  79 */     params.setLimit(limit);
/*  80 */     params.setResponseName(AdminConstants.SEARCH_GAL_RESPONSE);
/*  81 */     if (galAcctId != null) {
/*  82 */       params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
/*     */     }
/*  84 */     params.setResultCallback(new AdminGalCallback(params));
/*  85 */     GalSearchControl gal = new GalSearchControl(params);
/*  86 */     if (token != null) {
/*  87 */       gal.sync();
/*     */     } else
/*  89 */       gal.search();
/*  90 */     return params.getResultCallback().getResponse();
/*     */   }
/*     */   
/*     */   static class AdminGalCallback extends GalSearchResultCallback {
/*     */     private Element proxiedResponse;
/*     */     
/*     */     AdminGalCallback(GalSearchParams params) {
/*  97 */       super();
/*     */     }
/*     */     
/*     */     public boolean passThruProxiedGalAcctResponse()
/*     */     {
/* 102 */       return true;
/*     */     }
/*     */     
/*     */     public void handleProxiedResponse(Element resp)
/*     */     {
/* 107 */       this.proxiedResponse = resp;
/* 108 */       this.proxiedResponse.detach();
/*     */     }
/*     */     
/*     */     public Element getResponse()
/*     */     {
/* 113 */       if (this.proxiedResponse != null) {
/* 114 */         return this.proxiedResponse;
/*     */       }
/* 116 */       return super.getResponse();
/*     */     }
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 122 */     relatedRights.add(Rights.Admin.R_accessGAL);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/SearchGal.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */